public class test03 {
    public int[] searchRange(int[] nums, int target) {
        int rightRange = findRightRange(nums,target);
        int leftRange = findLeftRange(nums,target);
        if(rightRange==-2 || leftRange==-2){
            return new int[]{-1,-1};
        }
        if(rightRange-leftRange>1){
            return new int[]{leftRange+1,rightRange-1};
        }
        return new int[]{-1,-1};

    }

    private int findRightRange(int[] nums,int target){
        int rightRange = -2;
        int left = 0,right = nums.length-1;
        while(left<=right){
            int mid = left+(right-left)/2;
            if(nums[mid]>target){
                right = mid-1;
            }else{
                left = mid+1;
                rightRange = left;
            }
        }
        return rightRange;
    }

    private int findLeftRange(int[] nums,int target){
        int leftRange = -2;
        int left = 0,right = nums.length-1;
        while(left<=right){
            int mid = left+(right-left)/2;
            if(nums[mid]<target){
                left = mid+1;
            }else{
                right = mid-1;
                leftRange = right;
            }
        }
        return leftRange;
    }
}
